<template>
  <el-card class="update-log msg-table-list" style="height: 366px;">
    <div slot="header" class="clearfix">
      <span>待办任务（<span class="badge-arrow-num">{{this.total}}</span>）</span>
      <span class="header-more-title">
        <template >
          <router-link :to="'/task/todo-task'" class="link-type">
            <span>更多<i class="el-icon-arrow-right"></i></span>
          </router-link>
        </template></span>
    </div>
    <div class="body">
      <el-table v-loading="loading" :data="dataList" @row-click="handleTask" style="width: 100%;" :show-header="false">
        <template>
          <el-table-column prop="processName"></el-table-column>
          <el-table-column prop="startTime"></el-table-column>
        </template>
      </el-table>
    </div>
    <!-- 待办 -->
    <el-dialog :title="title" v-if="open" :visible.sync="open" width="800px" append-to-body>
      <task ref="task" :link="link" :businessId="businessId" :processParams="processParams"
            @submitVerify="submitVerify" @closeForm="closeForm"></task>
    </el-dialog>
    <!-- 伪待办 -->
    <el-dialog :title="fakeTitle" v-if="openFake" :visible.sync="openFake" width="1300px" append-to-body>
      <fake-task :link="link" :fakeTaskParams="fakeTaskParams" @closeFake="closeFake"/>
    </el-dialog>
  </el-card>
</template>

<script>
  import {taskPending} from '@/api/workflow/workFlow';
  import task from "@/views/workflow/form/task";
  import fakeTask from "@/views/workflow/form/fakeTask";

  export default {
    name: "TodoList",
    components: {
      task,
      fakeTask
    },
    data() {
      return {
        loading: true,
        dataList: [],
        //消息总数
        total: 0,
        title: "",
        // 查询参数
        queryParams: {
          pageParameter: { page: 1, rows: 7 },
          searchParams: {
            todoTaskStatus: '0'
          }
        },
        // 任务id
        taskId:undefined,
        taskVariables: undefined,
        processInstanceId: undefined,
        parentTaskId: undefined,
        businessKey: undefined, // 业务唯一标识
        visible: false,
        currProcessForm: '', //表单组件名称
        currFromControl: true, //控制属性
        // 流程参数
        processParams: {},
        // 伪待办标题
        fakeTitle: '',
        // 伪待办参数
        fakeTaskParams: {},
        // 伪待办开关
        openFake: false,
        // 业务表单路径
        link: '',
        // 业务id
        businessId: '',
        // 待办页开关
        open: false
      }
    },
    created() {
      this.initList();
    },
    methods: {
      initList() {
        this.loading = true;
        taskPending(this.queryParams).then(response => {
          this.dataList = response.responseBody.result;
          this.total = response.responseBody.pageParameter.totalCount;
          this.loading = false;
        })
      },
      handleTask(row) {
        // 0：伪待办，1：待办
        if(row.isFake === '0') {
          this.fakeTitle = row.currentNodeName
          this.link = row.link
          this.fakeTaskParams = {
            taskId: row.taskId
          }
          this.openFake = true
        }else {
          // 业务表里路径
          this.link = row.link
          // 业务id
          this.businessId = row.businessId
          // 流程参数
          this.processParams.taskId = row.taskId
          this.processParams.processId = row.processId
          this.processParams.processName = row.processName
          this.processParams.docUnid = row.docUnid
          this.processParams.currentNodeId = row.currentNodeId
          this.processParams.currentNodeName = row.currentNodeName
          this.processParams.startTime = row.startTime
          this.processParams.link = row.link
          this.processParams.businessId = row.businessId
          this.open = true
        }
      },
      //刷新
      refresh(){
        this.initList();
      },

      closeForm() {
        this.open = false
        this.initList()
      },
      submitVerify() {
        this.open = false
        this.initList()
      },

      // 回调
      closeFake() {
        this.openFake = false
        this.initList()
      },
    }
  }
</script>

<style lang="scss" scoped>
.el-table__row{
  cursor: pointer !important;
}
.el-table tr{
  cursor: pointer;
}
</style>
